<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@include file="/common/header.jsp"%>
<c:set var="path" value="..${ctx}/define/database" />

<div class="pageContent" layoutH="10">
	<form action="..${ctx}/upload/do.html" method="post" enctype="multipart/form-data" class="pageForm required-validate" onsubmit="return iframeCallback(this, dialogAjaxDoneUpload);">
		<input type="hidden" name="js_back_function" value="${js_back_function}" />
		<table width="90%" id="upload_table">
			<c:choose>
			<c:when test="${empty filenames}">
			<tr>
				<td>&nbsp;&nbsp;<label>选择文件：</label><input type="file" name="file.file[0]" /></td>
				<td><label>文件名称：</label><input type="text" name="file.name[0]" size="30" /></td>
				<td><a href="javascript:addFile();">添加</a>&nbsp;&nbsp;|&nbsp;&nbsp;
				<a name="del_upload_view" href="javascript:delFile(this);">删除</a></td>
			</tr>
			</c:when>
			<c:otherwise>
			<c:forEach var="filename" items="filenames" varStatus="index">
			<tr>
				<td>&nbsp;&nbsp;<label>选择文件：</label><input type="file" name="file.file[0]" /></td>
				<td><label>文件名称：</label><input type="text" name="file.name[${index}]" size="30" value="${filename}" /></td>
				<td><a href="javascript:addFile();">添加</a>&nbsp;&nbsp;|&nbsp;&nbsp;
				<a name="del_upload_view" href="javascript:delFile(this);">删除</a></td>
			</tr>
			</c:forEach>
			</c:otherwise>
			</c:choose>
		</table>

	<div class="formBar">
		<ul>
			<li><div class="button"><div class="buttonContent"><button type="submit" >提交</button></div></div></li>
			<li><div class="button"><div class="buttonContent"><button class="close" type="button">关闭</button></div></div></li>
		</ul>
	</div>
	</form>
</div>

<script type="text/javascript">
var index = 0;
	function addFile() {
		index = index + 1;
		id = "del_upload_view" + index;
		var txt = "<tr>"
		+ "<td>&nbsp;&nbsp;<label>选择文件：</label><input type='file' name='file.file[" + index + "]' /></td>"
		+ "<td><label>文件名称：</label><input type='text' class='textInput' name='file.name[" + index + "]' size='30' /></td>"
		+ "<td><a href='javascript:addFile();'>添加</a>&nbsp;&nbsp;|&nbsp;&nbsp;"
		//+ "<a name='del_upload_view' href='javascript:delFile();'>删除</a></td>";
		+ "<a id='" + id + "' href='javascript:delFile(\""+ id + "\");'>删除</a></td>";
		+"</tr>";
		$("#upload_table").append(txt); // 追加新元素
	}
	
	function delFile(name) {
		var trNode = $('#' + name).parent().parent();
		trNode[0].remove();
	}

    $(function () {
        $('a[name=del_upload_view]').click(function () {
            var trNode = $(this).parent().parent();
            trNode.remove();
        });
    });

/**
 * dialog上的表单提交回调函数
 * 服务器转回navTabId，可以重新载入指定的navTab. statusCode=DWZ.statusCode.ok表示操作成功, 自动关闭当前dialog
 * form提交后返回json数据结构,json格式和navTabAjaxDone一致
 */
function dialogAjaxDoneUpload(json) {
	DWZ.ajaxDone(json);
	if (json.statusCode == DWZ.statusCode.ok) {
		// alertMsg.correct(json.message);
		if (json.callbackType) {
			var funname = $("input[name='js_back_function']").val();
			if (funname != "") {
				var func = eval(funname);
				new func();
			}
			setTimeout(function() {
				$.pdialog.closeCurrent();
			}, 100); // 关闭此编辑页签
		}
	}
}
</script>
